package com.corpgovernment.common.apollo;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;

import java.util.Map;

/**
 * basic服务 apollo配置key集合
 */
@Component
public class BasicManageApollo extends CommonApollo {

    /**
     * 文件上传路径
     */
    @Value("${FastDFSUrl:}")
    private String fastDfsUrl;
    /**
     * 用户身份保存时长（分钟）
     */
    @Value("${user_register_valid_token_time_out:4}")
    private int userRegisterValidTokenTimeOut;
    /**
     * 登录超时时间（秒）
     */
    @Value("${login_time_out:7776000}")
    private long loginTimeOut;
    /**
     * 获取服务商key、security的配置，可根据公司服务商配置不同值
     */
    @Value("${supplier_ticket_json:{}}")
    private String supplierTicketJson;
    /**
     * 一个uid登录多个手机，按照登录时间降序推送的设备个数。
     */
    @Value("${push_num:3}")
    private int pushNum;
    /**
     * 验证码失效时间 单位:分钟
     */
    @Value("${msg_time_out:5}")
    private int msgTimeOut;
    /**
     * App站点的HOST地址
     */
    @Value("${app.host:}")
    private String appHost;
    /**
     * PCBOOK单点登录到PCADMIN超时时间,单位：秒
     */
    @Value("${single_login_time_out:1800}")
    private long singleLoginTimeOut;
    /**
     * 更新密码验证码有效期，单位：分钟
     */
    @Value("${update_pwd_valid_token_time_out:5}")
    private int updatePwdValidTokenTimeOut;
    /**
     * 单点登录外部系统跳转路径
     */
    @Value("${login_auth_out_direct:}")
    private String loginAuthOutDirect;
    /**
     * email.mailHost
     * 单点登录外部系统跳转url
     */
    @Value("${login_auth_out_direct_url:}")
    private String loginAuthOutDirectUrl;
    /**
     * 当前系统单点登录key
     */
    @Value("${login_auth_key:}")
    private String loginAuthKey;
    /**
     * 当前系统单点登录key
     */
    @Value("${login_auth_type:}")
    private String loginAuthType;
    /**
     * pcbook单点登录PC跳转页面
     */
    @Value("${pc_book_2_pc_redirect_url:pc}")
    private String pcBook2PcRedirectUrl;
    /**
     * 前端路由页面
     */
    @Value("${pc_book_2_pc_direct_str:pc}")
    private String pcBook2PcDirectStr;
    /**
     * 邮箱服务器域名
     */
    @Value("${email.mailHost:}")
    private String emailMailHost;
    /**
     * 邮箱服务器端口
     */
    @Value("${email.mailPort:}")
    private String emailMailPort;
    /**
     * 邮箱协议
     */
    @Value("${email.mailProtocol:}")
    private String emailMailProtocol;
    /**
     * 邮箱账号
     */
    @Value("${email.username:}")
    private String emailUserName;
    /**
     * 邮箱密码
     */
    @Value("${email.password:}")
    private String emailPassword;
    /**
     * oss账号
     */
    @Value("${aliyun.oss.keyId:}")
    private String aliyunOssAccessKeyId;
    /**
     * oss密码
     */
    @Value("${aliyun.oss.keySecret:}")
    private String aliyunOssAccessAccessKeySecret;
    /**
     * 阿里云上传文件bucket
     */
    @Value("${aliyun.oss.bucket:crectr}")
    private String aliyunOssBucket;

    /**
     * 阿里云上传文件bucket(私有资源)
     */
    @Value("${aliyun.oss.private.bucket:uat-private}")
    private String aliyunOssPrivateBucket;

    /**
     * 阿里云上传文件bucket(私有资源)
     */
    @Value("${aliyun.oss.expiration:3600}")
    private Long aliyunOssExpiration;

    /**
     * 阿里云上传文件查看url
     */
    @Value("${aliyun.oss.callback-url:}")
    private String aliyunOssCallbackUrl;
    /**
     * oss-endpoint地址
     */
    @Value("${aliyun.oss.endpoint:}")
    private String aliyunOssEndpoint;

    /**
     * sts-endpoint地址
     */
    @Value("${aliyun.sts.endpoint:cn-hangzhou}")
    private String aliyunStsEndpoint;


    /**
     * sts-roleArn
     */
    @Value("${aliyun.sts.role.arn:}")
    private String aliyunStsRoleArn;
    /**
     * oss 访问base路径
     */
    @Value("${aliyun.oss.access-base-path:test}")
    private String aliyunOssAccessBasePath;
    /**
     * oss最大size
     */
    @Value("${aliyun.oss.maxSize:500}")
    private int aliyunOssMaxSize;
    /**
     * oss过期时间（秒）
     */
    @Value("${aliyun.oss.policy.expire:5}")
    private int aliyunOssPolicyExpire;
    /**
     * 阿里云短信标签
     */
    @Value("${aliyun.sms.signature:商旅}")
    private String aliyunSmsSignature;
    /**
     * 阿里云短信域
     */
    @Value("${aliyun.sms.domain:dysmsapi.aliyuncs.com}")
    private String aliyunSmsDomain;
    /**
     * 阿里云短信版本
     */
    @Value("${aliyun.sms.version:2017-05-25}")
    private String aliyunSmsVersion;
    /**
     * 阿里云推送密钥
     */
    @Value("${aliyun.push.accesskey:}")
    private String aliyunPushAccesskey;
    /**
     * 阿里云推送密码
     */
    @Value("${aliyun.push.accesskey-secret:}")
    private String aliyunPushAccesskeySecret;
    /**
     * 阿里云推送区域
     */
    @Value("${aliyun.push.regionId:cn-hangzhou}")
    private String aliyunPushRegionId;
    /**
     * 阿里云安卓推送key
     */
    @Value("${aliyun.push.appkeyForAndroid:24770889}")
    private Long aliyunPushAppkeyForAndroid;
    /**
     * 阿里云IOS推送key
     */
    @Value("${aliyun.push.appkeyForIOS:24770889}")
    private Long aliyunPushAppkeyForIOS;
    /**
     * 阿里云推送apns环境
     */
    @Value("${aliyun.push.apnsEnv:DEV}")
    private String aliyunPushApnsEnv;
    /**
     * 是否需要文件上传
     */
    @Value("${needUpload:true}")
    private boolean needUpload;
    /**
     * 机信息场查询url
     */
    @Value("${searchFlightCityUrl:}")
    private String searchFlightCityUrl;
    /**
     * 机信息场查询url
     */
    @Value("${searchTrainStationCityUrl:https://ct.ctrip.com/SwitchAPI/Train/GetAllTrainStationAndCity}")
    private String searchTrainStationCityUrl;

    @Value("${mcisSrvCode:0}")
    private String mcisSrvCode;
    @Value("${mcisSocketHost:127.0.0.1}")
    private String mcisSocketHost;
    @Value("${mcisSocketPort:8080}")
    private int mcisSocketPort;
    @Value("${sendSmsType:CTRIP}")
    private String sendSmsType;
    @Value("${appPushSwitch:false}")
    private Boolean appPushSwitch;
    @Value("${otherResources:false}")
    private Boolean otherResources;

    public boolean isNeedUpload() {
        return needUpload;
    }

    @Value("${file_upload_type:}")
    private String fileUploadType;

    @Value("${tencent.cos.accessKey:}")
    private String accessKey;

    @Value("${tencent.cos.secretKey:}")
    private String secretKey;

    @Value("${tencent.cos.regionName:}")
    private String regionName;

    @Value("${tencent.cos.bucketName:}")
    private String bucketName;

    @Value("${whether.send.order.msg:true}")
    private Boolean whetherSendOrderMsg;

    @Value("${ctrip.sms.config:}")
    private String ctripSmsConfig;

    /**
     * 航司客规文案查询url
     */
    @Value("${flight.clause.configuration:}")
    private String flightClauseConfiguration;


    @Value("${send_msg_url:}")
    private String sendMsgUrl;



    @Value("${sync.train.basic.corp.id:}")
    private String syncTrainBasicCorpId;
    @Value("${sync.train.city.data.config:}")
    private String syncTrainCityDataConfig;
    /**
     * 火车票热点城市数据
     */
    @Value("${train.city.hotdata:}")
    private String trainCityHotData;
    /**
     * 国内机票热点城市数据
     */
    @Value("${flight.city.hotdata:}")
    private String flightCityHotData;
    /**
     * 国际机票热点城市数据
     */
    @Value("${intlflight.city.hotdata:}")
    private String intlflightCityHotData;
    /**
     * 国内酒店热点城市数据
     */
    @Value("${hotel.city.hotdata:}")
    private String hotelCityHotData;
    /**
     * 国际酒店热点城市数据
     */
    @Value("${intlhotel.city.hotdata:}")
    private String intlhotelCityHotData;

    /**
     * 同步国家数据url
     */
    @Value("${sync.country.basic.data.url:}")
    private String syncCountryBasicDataUrl;
    /**
     * 同步全量地理信息url（分销全量接口）
     */
    @Value("${sync.all.basic.data.url:}")
    private String syncAllBasicDataUrl;
    /**
     * 火车站城市数据（id,name,name_en,code）
     */
    @Value("${train.station.city.data.key:}")
    private String trainStationCityDataKey;

    public String getCtripSmsConfig() {
        return getAppProperty("ctrip.sms.config", "");
    }

    public String getSyncTrainBasicCorpId() {
        return getAppProperty("sync.train.basic.corp.id", "");
    }

    public String getSyncTrainCityDataConfig() {
        return this.getAppProperty("sync.train.city.data.config", "");
    }

    /**
     * 获取短信是否发送
     *
     * @return
     */
    public static boolean getZtSmsSend() {
        Config config = ConfigService.getAppConfig();
        return config.getBooleanProperty("zt.sms.send", true);
    }

    public String getFastDfsUrl() {
        return getAppProperty("FastDFSUrl", "");
    }

    public int getUserRegisterValidTokenTimeOut() {
        return Integer.parseInt(getAppProperty("user_register_valid_token_time_out", "4"));
    }

    public long getLoginTimeOut() {
        return Long.parseLong(getAppProperty("login_time_out", "7776000"));
    }

    public String getSupplierTicketJson() {
        return getAppProperty("supplier_ticket_json", "");
    }

    public int getPushNum() {
        return Integer.parseInt(getAppProperty("push_num", "3"));
    }

    public int getMsgTimeOut() {
        return Integer.parseInt(getAppProperty("msg_time_out", "5"));
    }

    public long getSingleLoginTimeOut() {
        return Long.parseLong(getAppProperty("single_login_time_out", "1800"));
    }

    public int getUpdatePwdValidTokenTimeOut() {
        return Integer.parseInt(getAppProperty("update_pwd_valid_token_time_out", "5"));
    }

    public String getLoginAuthOutDirect() {
        return getAppProperty("login_auth_out_direct", "");
    }

    public String getLoginAuthOutDirectUrl() {
        return getAppProperty("loginAuthOutDirectUrl", "");
    }

    public String getLoginAuthKey() {
        return getAppProperty("login_auth_key", "");
    }

    public String getPcBook2PcRedirectUrl() {
        return getAppProperty("pc_book_2_pc_redirect_url", "pc");
    }

    public String getPcBook2PcDirectStr() {
        return getAppProperty("pc_book_2_pc_direct_str", "pc");
    }

    public String getEmailMailHost() {
        return getAppProperty("email.mailHost", "");
    }

    public String getEmailMailPort() {
        return getAppProperty("email.mailPort", "");
    }

    public String getEmailMailProtocol() {
        return getAppProperty("email.mailProtocol", "");
    }

    public String getEmailUserName() {
        return getAppProperty("email.username", "");
    }

    public String getEmailPassword() {
        return getAppProperty("email.password", "");
    }

    public String getAliyunOssAccessKeyId() {
        return getAppProperty("aliyun.oss.keyId", "");
    }

    public String getAliyunOssAccessAccessKeySecret() {
        return getAppProperty("aliyun.oss.keySecret", "");
    }

    public String getAliyunOssBucket() {
        return getAppProperty("aliyun.oss.bucket", "crectr");
    }

    public String getAliyunOssPrivateBucket() {
        return getAppProperty("aliyun.oss.private.bucket", "uat-private");
    }

    public String getAliyunStsEndpoint() {
        return getAppProperty("aliyun.sts.endpoint", "cn-hangzhou");
    }

    public String getAliyunStsRoleArn() {
        return getAppProperty("aliyun.sts.role.arn", "acs:ram::1203537909779614:role/aliyunosstokengeneratorrole");
    }




    public Long getAliyunOssExpiration() {
        return Long.parseLong(getAppProperty("aliyun.oss.expiration", "3600"));
    }

    public String getAliyunOssCallbackUrl() {
        return getAppProperty("aliyun.oss.callback-url", "");
    }

    public String getAliyunOssEndpoint() {
        return getAppProperty("aliyun.oss.endpoint", "");
    }

    public String getAliyunOssAccessBasePath() {
        return getAppProperty("aliyun.oss.access-base-path", "test");
    }

    public int getAliyunOssMaxSize() {
        return Integer.parseInt(getAppProperty("aliyun.oss.maxSize", "500"));
    }

    public int getAliyunOssPolicyExpire() {
        return Integer.parseInt(getAppProperty("aliyun.oss.policy.expire", "5"));
    }

    public String getAliyunSmsSignature() {
        return getAppProperty("aliyun.sms.signature", "商旅");
    }

    public String getAliyunSmsDomain() {
        return getAppProperty("aliyun.sms.domain", "dysmsapi.aliyuncs.com");
    }

    public String getAliyunSmsVersion() {
        return getAppProperty("aliyun.sms.version", "2017-05-25");
    }

    public String getAliyunPushAccesskey() {
        return getAppProperty("aliyun.push.accesskey", "");
    }

    public String getAliyunPushAccesskeySecret() {
        return getAppProperty("aliyun.push.accesskey-secret", "");
    }

    public String getAliyunPushRegionId() {
        return getAppProperty("aliyun.push.regionId", "cn-hangzhou");
    }

    public Long getAliyunPushAppkeyForAndroid() {
        return Long.parseLong(getAppProperty("aliyun.push.appkeyForAndroid", "24770889"));
    }

    public Long getAliyunPushAppkeyForIOS() {
        return Long.parseLong(getAppProperty("liyun.push.appkeyForIOS", "24770889"));
    }

    public String getAliyunPushApnsEnv() {
        return getAppProperty("aliyun.push.apnsEnv", "DEV");
    }

    public String getSearchFlightCityUrl() {
        return getAppProperty("searchFlightCityUrl", "");
    }

    public String getSearchTrainStationCityUrl() {
        return getAppProperty("searchTrainStationCityUrl",
                "https://ct.ctrip.com/SwitchAPI/Train/GetAllTrainStationAndCity");
    }

    public String getMcisSocketHost() {
        return getAppProperty("mcisSocketHost", "127.0.0.1");
    }

    public int getMcisSocketPort() {
        return Integer.parseInt(getAppProperty("mcisSocketPort", "8080"));
    }

    public String getMcisSrvCode() {
        return getAppProperty("mcisSrvCode", "0");
    }

    public String getSendSmsType() {
        return getAppProperty("sendSmsType", "CTRIP");
    }

    public Boolean getAppPushSwitch() {
        return Boolean.parseBoolean(getAppProperty("appPushSwitch", "false"));
    }

    public String getLoginAuthType() {
        return getAppProperty("login_auth_type", "de79692d7e8cd326d14ec7e466242bd3");
    }

    public Boolean getOtherResources() {
        return Boolean.parseBoolean(getAppProperty("otherResources", "false"));
    }

    public String getFileUploadType() {
        return getAppProperty("file_upload_type", "");
    }

    public String getAccessKey() {
        return getAppProperty("tencent.cos.accessKey", "");
    }

    public String getSecretKey() {
        return getAppProperty("tencent.cos.secretKey", "");
    }

    public String getRegionName() {
        return getAppProperty("tencent.cos.regionName", "");
    }

    public String getBucketName() {
        return getAppProperty("tencent.cos.bucketName", "");
    }

    public String getAppKey() {
        return getAppProperty("appKey", "");
    }

    public String getAppSecurity() {
        return getAppProperty("appSecurity", "");
    }

    public Boolean getWhetherSendOrderMsg() {
        return Boolean.valueOf(getAppProperty("whether.send.order.msg", "true"));
    }

    public String getCtripHotelBasicCityUrl() {
        return getAppProperty("ctrip.hotel.basic.city.url", "");
    }

    public String getCtripHotelBasicCountryUrl() {
        return getAppProperty("ctrip.hotel.basic.country.url", "");
    }

    public String getFlightClauseConfiguration() {
        return getAppProperty("flight.clause.configuration", "");
    }

    public String getSendMsgUrl() {
        return getAppProperty("sendMsgUrl", "");
    }
    public String getTrainCityHotData(){
        return getAppProperty("train.city.hotdata", "");
    }
    public String getFlightCityHotData(){
        return getAppProperty("flight.city.hotdata", "");
    }
    public String getIntlflightCityHotData(){
        return getAppProperty("intlflight.city.hotdata", "");
    }
    public String getHotelCityHotData(){
        return getAppProperty("hotel.city.hotdata", "");
    }
    public String getIntlhotelCityHotData(){
        return getAppProperty("intlhotel.city.hotdata", "");
    }

    public String getSyncCountryBasicDataUrl() {
        return getAppProperty("sync.country.basic.data.url", "");
    }

    public String getSyncAllBasicDataUrl() {
        return getAppProperty("sync.all.basic.data.url", "");
    }

    public String getCurrencyExchangeRateUrl() {
        return getAppProperty("currency.exchange_rate.url", "");
    }

    public Map<String, String> getCurrencySupportMap(){
        String supportCurrencyMap = getAppProperty("currency.support_currency.map", "");
        return Convert.convert(new TypeReference<Map<String, String>>() {}, JSON.parseObject(supportCurrencyMap, Map.class));
    }

    public String getNameConfirmSwitch(){
        return getAppProperty("name.confirm.switch","false");
    }
    public String getCityTypeInfo() {
        return getAppProperty("city_type_info", "");
    }
    public String getCityTireTreeKeyData() {
        return getAppProperty("city_tire_tree_data", "");
    }
    public String getCountryBasicInfo() {
        return getAppProperty("country_basic_info", "");
    }
    public String getTrainStationCityDataKey(){
        return getAppProperty("train.station.city.data.key","train:station:cityDataKey");
    }
    public String getJianPinTireTreeKey() {
        return getAppProperty("tire_tree_jianPin_data", "");
    }
    public String getEnNameTireTreeKey() {
        return getAppProperty("tire_tree_enName_data", "");
    }
    public String getBasicOverseasCityList(){
        return getAppProperty("basic_overseas_city_list","");
    }
    public String getHotelDomesticHotCityList(){
        return getAppProperty("hotel_domestic_hot_city_list","");
    }
    public String getAlphabetIndexDomesticCityIds(){
        return getAppProperty("alphabet_index_domestic_city_ids","");
    }
    public String getAlphabetIndexOverseasCityIds(){
        return getAppProperty("alphabet_index_overseas_city_ids","");
    }
}
